﻿using System;

using OpenTK.Graphics.ES20;

using Storyteller.Framework.Graphics;

namespace Storyteller.Framework
{
	public abstract class Game
	{
		internal static Game InternalInstance { get; private set; }

		public int ScreenWidth { get; private set; }
		public int ScreenHeight { get; private set; }

		// todo: pass the window title down here

		public Game(string windowTitle, int screenWidth, int screenHeight)
		{
			if (InternalInstance != null)
				throw new InvalidOperationException("Cannot instantiate multiple Game objects");

			InternalInstance = this;

			ScreenWidth = screenWidth;
			ScreenHeight = screenHeight;
		}

		public void Clear(Color color)
		{
			GL.ClearColor(color.R, color.G, color.B, color.A);
			GL.Clear((int)All.ColorBufferBit);
		}

		public void LoadContentIOS()
		{
			LoadContent();
		}

		public void UnloadContentIOS()
		{
			UnloadContent();
		}

		public void UpdateIOS(float deltaSeconds)
		{
			Update(deltaSeconds);
		}

		public void DrawIOS()
		{
			Draw();
		}

		public void ChangeResolutionIOS(int width, int height)
		{
			ChangeResolution(width, height);
		}

		protected virtual void LoadContent() { }
		protected virtual void UnloadContent() { }

		protected virtual void Update(float deltaSeconds) { }
		protected virtual void Draw() { }

		protected virtual void ChangeResolution(int width, int height)
		{
			ScreenWidth = width;
			ScreenHeight = height;

			GL.Viewport(0, 0, width, height);
		}
	}
}
